﻿using System;
using DMS.BaseClass;
using DMS.Business.Modules.Organization;
using DMS.Business.Utility;

namespace DMS.Business.Modules.SupplierManagement
{
    /// <summary>
    /// 项目信息
    /// </summary>
    public class ProjectInfo
    {
        #region 数据成员
        private string _projectID = "";
        private string _projectCode = string.Empty;
        private string _projectName = string.Empty;
        private string _classID = "";
        private string _className = string.Empty;
        //private MaterialClass _materialClass = null;

        private string _creatorName = string.Empty;
        private string _creatorID = "";
        private DateTime _createTime = DateTime.MinValue;

        private User _creator = null;

        private StatusType _status = StatusType.Actived;
        #endregion

        #region 成员属性
        /// <summary>
        /// 项目信息唯一编码
        /// </summary>
        public string ProjectID
        {
            get
            {
                return this._projectID;
            }
            set
            {
                this._projectID = value;
            }
        }
        /// <summary>
        /// 项目编号
        /// </summary>
        public string ProjectCode
        {
            get
            {
                return this._projectCode;
            }
            set
            {
                this._projectCode = value;
            }
        }
        /// <summary>
        /// 项目名称
        /// </summary>
        public string ProjectName
        {
            get
            {
                return this._projectName;
            }
            set
            {
                this._projectName = value;
            }
        }

        /// <summary>
        /// 所属类别ID
        /// </summary>
        public string ClassID
        {
            get
            {
                return this._classID;
            }
            set
            {
                this._classID = value;
            }
        }

        /// <summary>
        /// 类别名称
        /// </summary>
        public string ClassName
        {
            get
            {
                return this._className;
            }
            set
            {
                this._className = value;
            }
        }

        ///// <summary>
        ///// 所属类别
        ///// </summary>
        //public MaterialClass MaterialClass
        //{
        //    get
        //    {
        //        if (this._materialClass == null && this._classID != Guid.Empty)
        //        {
        //            this._materialClass = MaterialHelper.GetMaterialClassByID(this._classID);
        //        }
        //        return this._materialClass;
        //    }
        //    set
        //    {
        //        this._materialClass = value;
        //        if (value != null)
        //        {
        //            this._classID = value.ClassID;
        //        }
        //        else
        //        {
        //            this._classID = Guid.Empty;
        //        }
        //    }
        //}

        /// <summary>
        /// 创建人ID
        /// </summary>
        public string CreatorID
        {
            get
            {
                return this._creatorID;
            }
            set
            {
                this._creatorID = value;
            }
        }
        /// <summary>
        /// 创建人姓名
        /// </summary>
        public string CreatorName
        {
            get
            {
                return this._creatorName;
            }
            set
            {
                this._creatorName = value;
            }
        }
        /// <summary>
        /// 创建人
        /// </summary>
        public User Creator
        {
            get
            {
                if (this._creator == null && this._creatorID != "")
                {
                    this._creator = UserHelper.GetUserByID(this._creatorID);
                }
                return this._creator;
            }
            set
            {
                this._creator = value;

                if (value != null)
                {
                    this._creatorID = value.ID;
                    this._creatorName = value.Name;
                }
                else
                {
                    this._creatorID = "";
                    this._creatorName = string.Empty;
                }
            }
        }

        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime CreateTime
        {
            get
            {
                return this._createTime;
            }
            internal set
            {
                this._createTime = value;
            }
        }
        /// <summary>
        /// 状态
        /// </summary>
        public StatusType Status
        {
            get
            {
                return this._status;
            }
            set
            {
                this._status = value;
            }
        }
        #endregion

        #region 构造函数
        public ProjectInfo()
        {
        }
        public ProjectInfo(string projectID)
        {
            this._projectID = projectID;
        }
        #endregion

        #region 成员方法

        /// <summary>
        /// 保存
        /// </summary>
        public void Save()
        {
            if (this._projectID == "")
            {
                User user = SystemContext.Current.LoginUser;
                this._projectID = Guid.NewGuid().ToString();
                this._creatorName = user.Name;
                this._creatorID = user.ID;
                this._createTime = DateTime.Now;

                ProjectHelper.AddProjectInfo(this);
            }
            else
            {
                ProjectHelper.UpdateProjectInfo(this);
            }
        }

        #endregion
    }
}
